/*
 * Copyright 2017 Zhongan.com All right reserved. This software is the
 * confidential and proprietary information of Zhongan.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Zhongan.com.
 */
package org.bird.concurrent;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 类CallableAndFutureDemo.java的实现描述：jdk回调实现样例
 * 
 * @author za-liangjianfei 2017年6月8日 上午9:58:04
 */
public class CallableAndFutureDemo {

    public static void main(String[] args) {
        Callable<Integer> callable = new Callable<Integer>() {

            public Integer call() throws Exception {
                return new Random().nextInt(100);
            }

        };
        FutureTask<Integer> futureTask = new FutureTask<Integer>(callable);
        new Thread(futureTask).start();
        try {
            Thread.sleep(5000);// 可能做一些事情
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
